package com;

import com.hazelcast.config.Config;
import com.hazelcast.config.GroupConfig;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.HttpServer;
import io.vertx.core.spi.cluster.ClusterManager;
import io.vertx.ext.web.Router;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Ldj
 * @Date 2017/11/2 9:30
 * @Description 数据处理
 */
public class App extends AbstractVerticle {
    public static void main(String[] args) {
        Config cfg = new Config();
        // 加入组的配置，防止广播环境下，负载串到别的开发机中
        GroupConfig group = new GroupConfig();
        group.setName("p-dev");
        group.setPassword("p-dev");
        cfg.setGroupConfig(group);
        // 申明集群管理器
        ClusterManager mgr = new HazelcastClusterManager(cfg);
        VertxOptions options = new VertxOptions();
        options.
                setWorkerPoolSize(100)
                .setClustered(true)
                .setHAEnabled(true)
                .setClusterManager(mgr)
                .setWarningExceptionTime(Long.MAX_VALUE);
        // 集群化vertx
        Vertx.clusteredVertx(options, ar -> {
            if (ar.succeeded()) {
                System.out.println(" successfully clusteredVertx!");
                final Vertx result = ar.result();
                result.deployVerticle(ApiVerticle.class.getName(), handle -> {
                    System.out.println("--------------成功");
                });
            } else {
                System.out.println("cluster failed, using default vertx");
            }
        });
    }
}
